/* 
* @Author: LDF QQ 47121862
* @Date:   2014-05-16 19:34:05
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-10-03 18:12:15
*/
// ;(function($){
// 扩展js
$(function(){
	//全局ajax等待样式
	// $(this).ajaxStart(function() {
	// 	$.msg({
	// 		str:getMsgTips('加载中...',3),
	// 		timeout:0,
	// 		shade:1
	// 	})
	// })
	// .ajaxStop(function() { //ajax成功时
	//     // $.closeMsg();
	// });

	//使用.ajax的链接或者标签触发ajax
	$('.ajax').click(function(){ $(this).lAjax(); return false; })

	//tab切换
	$('div.tabMenu a').bind('mouseover',function(){
		var i = $(this).index();
		$(this).addClass('act').siblings('a').removeClass('act');
		$('dl.tabSub dd').eq(i).show().siblings('dd').hide();
		return false;
	})
	//全选等
	$('#checkAll').click(function(){
		($(this).attr('checked'))?$('.table :checkbox').attr('checked','checked'):$('.table :checkbox').removeAttr('checked');
	})
	//模拟下拉框
	$('.selected').each(function(){
		$(this).chSelect();
	})
	//模拟下拉框2
	$('.selecteds').each(function(){
		$(this).chSelect(1);
	})
	//下拉菜单Menu右侧
	$('.Down').click(function(){
		$(this).find('.DownCont').show();
		return false;
	})
	$(document).click(function(){
		$('.DownCont').hide();
	})
	//返回顶部-------待完成
	$(document).scroll(function(){
		($(this).scrollTop()>500) ? $('.Fixed').fadeIn() : $('.Fixed').fadeOut();
	})
	$('.Fixed').click(function(){
		$('body,html').animate({'scrollTop':0})
	})
})
//================================================================================

//扩展开始
//ajax开始
$(function(){ //阻止表单回车提交
	$('form').keydown(function(e){
		if(e.keyCode==13){
			return false;
		}
	});
})
function ajax(id,go)
{
	var _form = $(id), _submit = _form.find("[type='submit']"), _subtext = _submit.html();
	_submit.attr('disabled','disabled').addClass('disabled');//提交按钮禁用；
	if(!_form.attr('action')){ //没有表单提交地址弹出提示信息
		$.msg({str:getMsgTips('表单没有提交地址，无法发送'),timeout:3,close:function(){
			_submit.removeAttr('disabled').removeClass('disabled');//提交按钮解禁；
		}});
		return false;
	}
	//取得ajax所需信息 根据表单method选择发送方式，默认为get方式发送
	var url = _form.attr('action'), meth = _form.attr('method') || 'get';
	$.ajax({
		url: url,
		type:meth,
		dataType:'json',
		data:_form.serialize(),
		beforeSend:function(){
			_submit.html(getMsgTips('加载',4)); //请求ajax提交按钮显示加载中图
		},
		success:function(re){
			_submit.html(_subtext); //恢复提交按钮原文字
			if(re.err == '1'){ //有错误发生
				var title = re.title || '操作失败，请重试...';
				$.msg({str:getMsgTips(title,2),timeout:3,close:function(){
					_submit.removeAttr('disabled').removeClass('disabled');//提交按钮解禁；
				}});
			}else{
				var title = re.title || '恭喜，操作成功！';
				$.msg({str:getMsgTips(title,1),timeout:3,close:function(){
					if(go && typeof go == 'string'){ //有跳转地址就跳转
						location.href = go;
					}else if(typeof go == 'number' && go == '1'){ //刷新当前页面
						location.reload();
					}
				}});
			}
		}
	})
	return false;
}
function getMsgTips(str,opt){ //获取msg提示信息1正确 2错误 3加载 4加载图标 默认 警告 
	switch(opt)
	{
		case 1:return '<div class="p5"><i class="icon-ok-circle icon-large green-3 f28 vmd mr40"></i> <span class="vm fm f16 green">'+str+'</span></div>';
		case 2:return '<div class="p5"><i class="icon-remove-circle icon-large red-3 f28 vmd mr40"></i> <span class="vm fm f16 red">'+str+'</span></div>';
		case 3:return '<div class="p5"><i class="icon-spinner icon-spin icon-large green f28 vm mr5"></i> <span class="vm fm f16 green">'+str+'</span></div>';
		case 4:return '<i class="icon-spinner icon-spin icon-large mr5"></i>'+str;
		default:return '<div class="bd1 bdyellow-2 bgyellow5 p5"><i class="icon-warning-sign icon-large orange-3 f22 vmd mr30"></i> <span class="vm fm f16 orange-2">'+str+'</span></div>';
	}
}
$.fn.extend({
	lAjax:function(){ //普通标签ajax 默认以get方式发送，参数通过href传递
		var id = $(this), url = id.attr('href') || '', go = id.attr('data-url') || '', atxt = id.html();
		id.removeAttr('href').addClass('disabled');//a链接禁用；
		if(!url){ //没有链接地址时
			$.msg({str:getMsgTips('没有提交地址，无法发送'),shade:1,timeout:3,close:function(){ 
				id.removeClass('disabled') //恢复a链接
			}});return false;
		}
		$.ajax({
			url: url,
			type:'get',
			dataType:'json',
			beforeSend:function(){
				id.html(getMsgTips('',4)); //请求ajax提交按钮显示加载中图
			},
			success:function(re){
				id.html(atxt); //恢复原文字
				if(re.err == '1'){ //有错误发生
					var title = re.title || '操作失败，请重试...';
					$.msg({str:getMsgTips(title,2),shade:1,timeout:3,close:function(){
						id.attr('href',url); id.removeClass('disabled') //恢复a链接
					}});
				}else{
					var title = re.title || '恭喜，操作成功！';
					$.msg({str:getMsgTips(title,1),shade:1,timeout:3,close:function(){
						id.attr('href',url); id.removeClass('disabled') //恢复a链接
						if(go && go != '1'){ //有跳转地址就跳转
							location.href = go;
						}else if(go && go == '1'){ //刷新当前页面
							location.reload();
						}
					}});
				}
			}
		})
		// $.get(url,function(re){
		// 	if(re.err == '1'){ //有错误发生
		// 		var title = re.title || '操作失败，请重试...';
		// 		$.msg({str:getMsgTips(title,2),shade:1,timeout:3,close:function(){
		// 			id.attr('href',url); id.removeClass('disabled') //恢复a链接
		// 		}});
		// 	}else{
		// 		var title = re.title || '恭喜，操作成功！';
		// 		$.msg({str:getMsgTips(title,1),shade:1,timeout:3,close:function(){
		// 			id.attr('href',url); id.removeClass('disabled') //恢复a链接
		// 			if(go && go != '1'){ //有跳转地址就跳转
		// 				location.href = go;
		// 			}else if(go && go == '1'){ //刷新当前页面
		// 				location.reload();
		// 			}
		// 		}});
		// 	}
		// },'json')
	}
})
//ajax结束
$.fn.extend({
	pos:function(rand){ //居中
		var t = ($(window).height() - $(this).height())/4 + $(window).scrollTop();
			 l = ($(window).width() - $(this).width())/2,
			 radt=Math.floor(Math.random()*($(window).height() - $(this).height())),
			 radl=Math.floor(Math.random()*($(window).width() - $(this).width()));
		if(rand){
			$(this).css({left:radl,top:radt}).animate({'top':t,'left':l}); //随机出现方式
		}else{
			$(this).css({'top':t,'left':l}); //普通方式
		}
		return this;
	},
	drag:function(option){ //拖拽,默认不限制范围
		var opt={
			limit:0, 	//是否限制范围 0 不限制 1 限制
			title:0 //是不是标题，1是标题就拖动上级 0拖动自己
		};
		opt=$.extend(opt,option); //合并参数
		var id = $(this);
		var obj = !opt.title ? $(this) : $(opt.title);
		obj.css('cursor','move');
		obj.mousedown(function(e){
			var _t = !opt.title ? $(this) : $(this).parent();
			var ls = e.pageX - _t.position().left,
			 	 ts = e.pageY - _t.position().top,
			 	 w = !opt.limit ? $(window).width() - _t.width() + $(window).scrollLeft() : id.parent().width() - _t.width() + id.parent().scrollLeft(),
			 	 h = !opt.limit ? $(window).height() - _t.height() + $(window).scrollTop() : id.parent().height() - _t.height() + id.parent().scrollTop(),
			 	 _this= !opt.title ? $(this) : $(this).parent();	
			$(document).on('mousemove',function(e){
				var l = e.pageX -ls,
			 	 	 t = e.pageY - ts;	
				_this.css({'left':l,'top':t});
				if(opt.limit){
					if(_this.position().left<=0)
						_this.css('left',0);
					if(_this.position().top<=0)
						_this.css('top',0);
					if(_this.position().left>=w)
						_this.css('left',w);
					if(_this.position().top>=h)
						_this.css('top',h);
				}
			})
			return false;
		})
		$(document).on('mouseup',function(){
			$(document).off('mousemove');
		})
		return this;
	},
	showPic:function(option){//自动显示大图
		var timer=null,id=$(this),
			opt={
				fllow:0, //是否开启跟随
				time:100, //多少秒后出现图片
				e:{left:10,top:10} //图片距离鼠标位置
			};
		opt = $.extend(opt,option);
		var h=null;
		$(this).hover(function(e){
			var pic = $(this).children('img').attr('src'),
				 p = $(this).children('img');
			h = $('<img class="showPicCont" src='+pic+' />');
			if($('.showPicCont').length==0) $('body').append(h);
			if(opt.fllow){ //是否开启鼠标跟随
				$(document).on('mousemove',function(ev){
					var l = ev.pageX+opt.e.left,
		 	 				t = ev.pageY+opt.e.top;
					id.showPicFn(l,t);
			 	}); 
			}else{
				$(document).off('mousemove');
				timer=setTimeout(function(){
					var l = e.pageX+opt.e.left,
		 	 				t = e.pageY+opt.e.top;
					id.showPicFn(l,t);
				},opt.time)
			}
		},function(){
			h.remove();
			clearTimeout(timer);
		})
		id.showPicFn=function(l,t){ //图片出现
			var sp = $('.showPicCont')
		 	 lmax = $(window).outerWidth()+$(window).scrollLeft()-sp.outerWidth(),
		 	 tmax = $(window).outerHeight()+$(window).scrollTop()-sp.outerHeight();
		 	 sp.fadeIn().css({'left':l,'top':t});
		 	 if(l>lmax) sp.css('left',lmax);
		 	 if(l<=0) sp.css('left',l);
		 	 if(t<=0) sp.css('top',t);
		 	 if(t>tmax) sp.css('top',tmax);
		}
	},
	chSelect:function(opt){ //模拟下拉框
		var _name=$(this).attr('name'),_this=$(this),
			sel='<div class="chSelect selected">',op='<div class="subSelect">',
			opFirst=$(this).find('option').first().text(),
			inp='<input type="hidden" name="'+_name+'" />',actValue=null,actName=null;
		this.bornOption=function(){ //生成option
			_this.find('option').each(function(){
				var val = $(this).val(),opName = $(this).text(),opDisabled=$(this).attr('disabled'),
					opSelected=$(this).attr('selected');
					opSelected = opSelected?'selected="selected"':'';
				if(opDisabled) { //增加disabled属性
					opDisabled = 'disabled';
					op+='<p class="sub '+opDisabled+'" value="'+val+'" disabled='+opDisabled+' '+opSelected+'>'+opName+'</p>';
				}else{
					op+='<p class="sub" value="'+val+'" '+opSelected+'>'+opName+'</p>';
				}
			})
		}
		this.bornSelect=function(){ //生成Select
			this.bornOption()	;
			sel+='<b class="selVal">'+opFirst+'</b><i class="Down"></i>'+op+'</div></div>';
			_this.parent().append(sel).append(inp).end().remove();
		}

		this.bornSelect();

		// var select = $('.chSelect'),subSel=select.children('div'),ops=subSel.children('p'),_input=$('input[name="'+_name+'"]'),selVal = select.children('.selVal');
		this.addEv=function(){ //增加点击事件
			var select = $('.chSelect'),_input=$('input[name="'+_name+'"]');
			select.each(function(i){
				var _stat=0;
				$(this).click(function(){
					var _this=$(this),subSel=_this.children('div'),ops=subSel.children('p'),selVal = _this.children('.selVal'),stat=0;
					if(opt){
						if(subSel.height()>=300 && _stat==0){
							var _width=(_this.outerWidth()-2)*4;
							ops.css({'display':'inline-block','border':'1px solid #eee','margin':'2px'});
							_stat =1;
						}else{
							if(_stat==0) var _width=(_this.outerWidth()-2);
						}
					}else{
						var _width=(_this.outerWidth()-2);
					}
					subSel.css({'top':_this.outerHeight()-2,'left':'-1px','width':_width});
					subSel.slideDown();
					ops.click(function(){ //下拉框点击事件
						var _val = $(this).attr('value'),_name=$(this).text();
						if($(this).attr('disabled')) return false;
						_input.val(_val);
						selVal.text(_name);
						subSel.slideUp(100);
						return false;
					})
					return false;
				})
				Down.click(function(event) {
					$(this).trigger('click');
				});
				//默认选中selected
				var ops = $(this).children('div').children('p'),selVal = $(this).children('.selVal');
				ops.each(function(){
					if($(this).attr('selected')) {
						actValue = $(this).attr('value');
						actName = $(this).text();
					}
				})
				selVal.text(actName);
				_input.val(actValue);

			})
			$(document).click(function(){
				select.children('div').slideUp(100);
			})
		}
		this.addEv();
	},
	FlyNums:function(fn){ //飞翔的数字
		var f=$(this),num=f.find('.Num'),_H=f.outerHeight(true),_W=f.outerWidth(true),h='<div class="FlyCont" style="position:absolute;">+1</div>',re=parseInt(num.text())+1;
		f.css('position','relative');
		num.text(re);
		f.append(h);
		var flycont=$('.FlyCont'),FW=(_W-flycont.outerWidth(true))/2;
		flycont.html('+'+re);
		flycont.css({'left':FW+'px','top':'15px'}).animate({'top':-_H+'px','fontSize':'10px','opacity':0},1000,function(){
			flycont.remove();
			if(fn) fn();
		})
	}
})
$.extend({
	//弹窗消息
	msg:function(options){
		$.closeMsg();   //只允许有一个窗口存在，就是先清除弹出框

		var _this=this,
			 _def={
			 	str:'欢迎使用：LDF(老地方)简单弹出消息窗口！', //默认内容
			 	timeout:2, //关闭时间
			 	shade:0, //是否有遮罩
			 	closebtn:0, //是否显示关闭按钮
			 	randPos:0, //是否以随机方式出现和关闭
			 	css:{width:null,height:null}, //自定义窗口大小
			 	close:function(){} //回调函数
			 },
			 opt = $.extend(_def,options),
			 timer=null;
			 _this.ind = 0; //id标记
		this.close=function(){
			var radt=Math.floor(Math.random()*$(window).height()-50),
			 	radl=Math.floor(Math.random()*$(window).width()-50);
			if(m.length<=1) _this.ind=0;
			if(opt.randPos){ //随机显示关闭
				m.eq(_this.ind).animate({left:radl,top:radt,width:0,height:0,opacity:.5},function(){
					$(this).remove();
					opt.close();
				})
			}else{
				m.eq(_this.ind).animate({opacity:.0},function(){
					$(this).remove();
					opt.close();
				})
			}
			// m[_this.ind].remove();
			bg.remove();
			_this.ind++;
			return this;
		}
		var d = $.getSize($(document)),div='',bg='';
		bg+='<div class="msgContentClassBg"></div>'
		div += '<div class="msgContentClass"><div class="msgContentBorder"></div>\
			<b class="closeMsgB">×</b><div class="msgContentStr">\
			'+opt.str+'</div></div>';
		if($('div.msgContentClass').length<=5){ //限制窗口不超过5个
			$('html').append(bg).append(div);
		}
		var bg = $('.msgContentClassBg'),m=$('.msgContentClass'),c=$('.closeMsgB'),ms=$('.msgContentClass .msgContentStr');
		if(opt.shade) bg.width((d.w)).height((d.h)).css({'opacity':.3,'top':0,'left':0}).fadeIn();
		if(!opt.closebtn) c.remove();
		m.fadeIn();
		if(opt.css.width)  m.css({'width':opt.css.width+'px','height':opt.css.height+'px'}) ;
		m.css({'width':ms.outerWidth(true),'height':ms.outerHeight(true)});
		(opt.randPos) ? m.pos(1) : m.pos(); //显示方式是否随机
		if(opt.timeout){
			timer=setTimeout(function(){
				_this.close();
			},opt.timeout*500)
		}
		$(document).on({'keydown':function(e){
			if(e.keyCode==27) {
				clearTimeout(timer);
				_this.close();
				return false;
			}	
		}})
		c.click(function(){
			clearTimeout(timer);
			_this.close();
			opt.close();
		})
		return this;
	},
	closeMsg:function(){
		var bg = $('.msgContentClassBg'),m=$('.msgContentClass'),c=$('.closeMsgB'),mb=$('.msgContentBorderClass');
		m.remove();mb.remove();bg.remove();
	},
	getSize:function(id){ //获得尺寸
		var s = {};
		s.w = id.width();
		s.h = id.height();
		s.l = id.scrollLeft();
		s.t = id.scrollTop();
		return s;
	},
	confirmd:function(options){ //确认框 模态
		var _def={ yes:null, no:null, msg:'您确定要继续吗?' },
			 opt = $.extend(_def, options);
		$.addConfirmd(opt.msg);
		var c = $('.LDFconfirm'),
			 bg = $('.msgContentClassBg'),
			 d = $.getSize($(document)),
			 yes = c.find('.yes'),
			 no = c.find('.no'),
			 re = null;
		bg.width((d.w)).height((d.h)).css({'opacity':.3,'top':0,'left':0}).fadeIn();
		c.pos();yes.focus();
		$(document).on({'keydown':function(e){
			$.delConfirmd();
			if(e.keyCode==13) {
				if(opt.yes){
					opt.yes();
				}
				return true;
			}else{
				if($('.LDFconfirm').length > 0){
					if(opt.no) {
						opt.no();
					}
				}
				return false;
			}	
		}})
		yes.live('click',function(){
			if(opt.yes) opt.yes();
			$.delConfirmd();
			return true;
		})
		no.bind('click',function(){
			if(opt.no) opt.no();
			$.delConfirmd();
			return false;
		})
	},
	addConfirmd:function(str){ //添加模态
		var confirmHmtl = '\
		<div class="msgContentClassBg"></div>\
		<div class="LDFconfirm">\
			<p class="cont">'+str+'</p>\
			<p class="bottom">\
				<a href="javascript:;" class="yes">确定</a>\
			 	<a href="javascript:;" class="no">取消</a>\
			</p>\
		</div>\
		';
		$('body').append(confirmHmtl);
	},
	delConfirmd:function(){ //删除模态框
		$('.msgContentClassBg').remove();
		$('.LDFconfirm').animate({top:0,opacity:0},function(){$(this).remove()});
	}
});
//表单验证
$.fn.extend({
	validate:function(opt){
		var form=$(this),ns=0,err=9,totalOpt=0,re=0,
		_fn={
			nonull:function(name,val){ //不能为空
				var name = form.find('[name='+name+']');
					re = ($.trim(name.val()) != '')?1:0;
				this.showMsg(name,re);
			},
			len:function(name,val){ //限制字符范围
				var name = form.find('[name='+name+']'),
					num=val.split(','),min=parseInt(num[0]),max=parseInt(num[1]);
				re = (name.val().length<min || name.val().length>max)?0:1;
				this.showMsg(name,re);
			},
			maxlen:function(name,val){ //字符最大范围
				var name = form.find('[name='+name+']');
					re = ($.trim(name.val()).length>val || $.trim(name.val()) == '')?0:1;
				this.showMsg(name,re);
			},
			two:function(name,val){ //比较两个表单是否相等
				var name = form.find('[name='+name+']'),
					other = form.find('[name='+val+']');
					re = ($.trim(name.val())==$.trim(other.val()))?1:0;
				this.showMsg(name,re);
			},
			regexp:function(name,val){ //自定义正则
				var name = form.find('[name='+name+']');
					re = val.test(name.val())?1:0;
				this.showMsg(name,re);
			},
			tel:function(name,val){ //固定电话 8位
				var name = form.find('[name='+name+']');
					re = /(?:\(\d{3,4}\)|\d{3,4}-?)\d{8}/.test(name.val())?1:0;
				this.showMsg(name,re);
			},
			phone:function(name,val){ //手机
				var name = form.find('[name='+name+']');
					re = /^\d{11}$/.test(name.val())?1:0;
				this.showMsg(name,re);
			},
			qq:function(name,val){ //QQ号码
				var name = form.find('[name='+name+']');
					re = /^\d{5,12}$/.test(name.val())?1:0;
				this.showMsg(name,re);
			},
			email:function(name,val){ //邮箱
				var name = form.find('[name='+name+']');
					re = /^([a-zA-Z0-9_\-\.])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/i.test(name.val())?1:0;
				this.showMsg(name,re);
			},
			www:function(name,val){ //网址
				var name = form.find('[name='+name+']');
					re = /^(http[s]?:)?(\/{2})?([a-z0-9]+\.)?[a-z0-9]+(\.(com|cn|cc|org|net|com.cn))$/i.test(name.val())?1:0;
				this.showMsg(name,re);
			},
			id:function(name,val){ //身份证
				var name = form.find('[name='+name+']');
					re = /^(\d{15}|\d{18})$/.test(name.val())?1:0;
				this.showMsg(name,re);
			},
			warning:function(name){ //警告，红白相互间隔
				var _t=name,timer=null,k=6;
				_t.addClass('formError');
				timer=setInterval(function(){
					if(k<=0){
						clearInterval(timer);
						_t.removeClass('formWarning');
					}else{
						_t.toggleClass('formWarning');
					}
					k--;
				},50);
				return this;
			},
			showMsg:function(obj,re){ //显示处理结果
				if(re==1){
					obj.removeClass('formError');
				}else{
					if(ns<totalOpt) this.warning(obj);
				}
				ns++; //表单第一次醒目显示
				err=form.find('.formError').length;
			},
			lost:function(name){ //表单失去焦点时，触发验证
				form.live('blur',function(event, send){
					for(method in opt[name]){
						if(_fn[method]){
							_fn[method](name,opt[name][method]);
						}
					}
				})
			}
		};
		for(var name in opt){
			totalOpt++; //对象个数
			_fn.lost(name);
		}
		form.submit(function(){ //表单提交时候触发验证机制
			if(!err) form.submit();
			for(var name in opt){
				var obj = $('[name='+name+']');
				for(var method in opt[name]){
					_fn[method](name,opt[name][method]);
					// eval('_fn.'+method+'(" '+name+' "," '+opt[name][method]+' ")');
				}
			}
			return false;
		});
	}
});
//幻灯片
$.fn.extend({
	slide:function(option)
	{
		var opt={
			moveStyle:'x', 	//运动方向 x水平 y垂直
			time:5000, 			//时间间隔 毫秒
			moveTime:1000, 	//动画时间间隔 毫秒
			rand:true, 			//是否开始随机动画
			bgPos:'bottom', 	//内容显示位置 'up' , 'down'
			numPos:'bottom', 	//数字显示位置 'up' , 'down'
			isBg:true 			//内容背景是否显示
		};
		opt=$.extend(opt,option); //合并参数
		var timer=null,c=0,s={},_this=$(this),pic=_this.children('.pic'),a=pic.children('a');
		s.getOpt=function(){ //根据参数获取样式
			// 显示位置 上或下
			var bgPos = (opt.bgPos=='up') ? 'top:0;' : 'bottom:0;' ;
			var numPos = (opt.numPos=='up') ? 'top:0;' : 'bottom:0;' ;
			return {bgPos:bgPos,numPos:numPos};
		}
		s.move=function() 
		{ //图片和数字运动以及标题的改变 
			var rand = $.randAnimate(opt.rand);
			switch(opt.moveStyle){
				case 'x':
					a.css('float','left');
					var pos=c*-a.eq(c).outerWidth(true);
					// pic.stop().animate({'marginLeft':pos},{easing: rand,duration: opt.moveTime})
					pic.stop().animate({'marginLeft':pos},opt.moveTime,rand);
				break;
				default:
					var pos=c*-a.eq(c).outerHeight(true);
					// pic.stop().animate({'marginTop':pos},{easing: rand,duration: opt.moveTime})
					pic.stop().animate({'marginTop':pos},opt.moveTime,rand);
				break;
			}
      	//数字移动
      	this.num.eq(c).addClass('act').siblings().removeClass('act');
      	//更改标题
      	if(opt.isBg) this.bgCont.html(a.eq(c).attr('title'));
		}
		s.addNum=function()
		{ //根据图片数量添加数字以及标题背景
			var style=s.getOpt();
			if(opt.isBg) var aTitle=a.eq(0).attr('title');
			var html='<div class="nums" style="z-index: 5;'+style.numPos+';">';
			for(var i=1; i<=a.length; i++)
			{
				html+=(i==1)?'<b class="act">'+i+'</b>':'<b>'+i+'</b>';
			}
			html+='</div>';
			if(opt.isBg){ //控制内容是否显示
				html+='\
					<div class="bgCont" style="position: absolute;z-index: 2;'+style.bgPos+'">'+aTitle+'</div>\
					<div class="bg" style="position: absolute;z-index: 1;'+style.bgPos+'"></div>\
				';
			}
			_this.append(html);
			this.num = _this.find('.nums').children('b'); //以下都是s的属性
			this.bgCont =_this.find('.bgCont'); 
			this.bg = _this.find('.bg'); 
		}
		s.addEv=function()
		{ //增加鼠标事件
			a.hover(function(){
				clearInterval(timer);
			},function(){
				s.auto();
			})
			this.num.hover(function(){
				clearInterval(timer);
				c=$(this).index();
				s.move();
			},function(){
				s.auto();
			})
		}
		s.auto=function()
		{ //自动运行
			timer=setInterval(function(){
				c++;
				if(c>=a.length) c=0;
				s.move();
			},opt.time)
		}
		s.addNum();
		s.addEv();
		s.auto();
	}
})
//随机动画
$.extend({  //rand穿参为：boolean 或者 动画名称
	randAnimate : function(rand)
	{
		if(!rand) //是否开启随机动画
		{
			// var moveType = ['linear'];
			var moveType = ['easeOutQuint'];
		}
		else
		{
			var moveType=( typeof rand == "string") ? [rand] : [
				'linear','easeInBounce','easeOutBounce','easeInOutBounce','easeInBack','easeOutBack','easeInOutBack','easeInElastic','easeOutElastic','easeInOutElastic','easeInQuart','easeOutQuart','easeInOutQuart'
			];
		}
		return moveType[parseInt(Math.random()*moveType.length)];
	}
})
//滚动图片
$.fn.extend({
	imgScroll:function(option){
		var opt={
			moveStyle:'x', 	//运动方向 x水平 y垂直
			one: 1 , //每次滚动1个图片还是整个可视区域
			time:2000, 			//时间间隔 毫秒
			moveTime:1000, 	//动画时间间隔 毫秒
			rand:1 			//是否开始随机动画
		};
		opt=$.extend(opt,option); //合并参数
		var _this=$(this) ,
			s = {} , timer = null , c = 0 ,
			pic = _this.children('.pic') ,
			a = pic.find('a') ,
			left = _this.children('.left') ,
			right = _this.children('.right') ,
			aW = a.eq(c).outerWidth(true) ,
			aH = a.eq(c).outerHeight(true) ,
			pW = _this.outerWidth(true) ,
			ms = parseInt(pW/aW+1);
		s.move=function(){ //图片滚动，带判断。
			var om = (opt.one) ? (a.length - ms) : ((a.length / ms)-1 ), 
				o =  (opt.one) ? c >= om : c > om;
			if(o){
				c=0 ;
			}else if(c<0){
				c = om;
			}
			var  l = (opt.one) ? (-aW * c) : (-aW * c) * ms ;
			var rand = $.randAnimate(opt.rand);
			// pic.stop().animate({'marginLeft':l},{easing: rand,duration: opt.moveTime}) ;
			pic.stop().animate({'marginLeft':l},opt.moveTime,rand);
		}
		s.addEv = function(){ //左右按钮添加事件
			var _s = this;
			_this.hover(function(){
				clearInterval(timer);
				left.add(right).fadeIn();
			},function(){
				left.add(right).fadeOut();
				_s.auto();
			})
			left.click(function(){
				c++;
				_s.move();
			})
			right.click(function(){
				c--;
				_s.move();
			})
		}
		s.auto=function(){ //自动滚动
			clearInterval(timer);
			var _s = this;
			timer = setInterval(function(){
				c++;
				_s.move();
			},opt.time)
		}
		s.addEv();
		s.auto();
	}
});
// 尾随效果
$.fn.extend({
	trailing:function(option){
		var opt={
			moveTime:100, 	//动画时间间隔 毫秒
			rand:0 			//是否开始随机动画
		};
		opt=$.extend(opt,option); //合并参数
		$(this).bind('mouseenter mouseleave',function(e){
			var w = $(this).outerWidth(),
					h = $(this).outerHeight(),
					x = (e.pageX - this.offsetLeft - (w / 2)) * (w > h ? (h / w) : 1),
					y = (e.pageY - this.offsetTop - (h / 2)) * (h > w ? (w / h) : 1),
					dir =  Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4, //值为'0,1,2,3'分别对应着'上,右,下,左'  
					etype = e.type == 'mouseenter' ? 1 : 0,
					enter = new Array('0px','0px','0px','0px'), //进入
					leave = new Array(-h,w,h,-w), //移出
					bg = $(this).children('.bg');
					var rand = $.randAnimate(opt.rand);
					if(etype){ //进入
						switch(dir){
		         	case 0:bg.show().css({'top':-h,'left':0}).stop().animate({'top':enter[dir]},opt.moveTime,rand);break;
		         	case 1:bg.show().css({'left':w,'top':0}).stop().animate({'left':enter[dir]},opt.moveTime,rand);break;
		         	case 2:bg.show().css({'top':h,'left':0}).stop().animate({'top':enter[dir]},opt.moveTime,rand);break;
		         	case 3:bg.show().css({'left':-w,'top':0}).stop().animate({'left':enter[dir]},opt.moveTime,rand);break;
		         }
					}else{ //移出
						switch(dir){
		         	case 0:bg.stop().animate({'top':leave[dir]},opt.moveTime,rand,function(){bg.hide()});break;
		         	case 1:bg.stop().animate({'left':leave[dir]},opt.moveTime,rand,function(){bg.hide()});break;
		         	case 2:bg.stop().animate({'top':leave[dir]},opt.moveTime,rand,function(){bg.hide()});break;
		         	case 3:bg.stop().animate({'left':leave[dir]},opt.moveTime,rand,function(){bg.hide()});break;
		         }
					}
		})
	}
})



	//获取浏览器版本
	$.extend({
		getBrower : function(){
			if($.browser.msie&&($.browser.version == "6.0")) return 6;
			if($.browser.msie&&($.browser.version == "7.0")) return 7;
			if($.browser.msie&&($.browser.version == "8.0")) return 8;
			return 0;
		}
	});
	//滚动监听导航菜单
	$.fn.extend({
		scrollMenu : function(option)
		{
			var _t = option || 0;
			var _sm = $(this), _sma = _sm.children('a');
			if(!_sm.attr('position')) _sm.css('position','absolute');
			$(window).scroll(function(e){
				var _wt = $(window).scrollTop();
				_sm.stop().animate({top:_wt+50+'px',opacity:.3},300,function(){ _sm.animate({opacity:1},200); }).drag();
				_sma.each(function(i){
					var href = _sma.eq(i).attr('href');
					if($(href).position().top - _wt <= _t){
						_sma.eq(i).addClass('act').siblings().removeClass('act');
					}
				})
			});
		}
	})

//集成tween动画
$.easing.linear = function (x, t, b, c, d) { return c*t/d + b; };
// Bounce
$.easing.easeInBounce = function (x, t, b, c, d) { return c - $.easing.easeOutBounce(x, d-t, 0, c, d) + b; };
$.easing.easeOutBounce = function (x, t, b, c, d) {
	if ((t/=d) < (1/2.75)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)) {
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)) {
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	}
};
$.easing.easeInOutBounce = function (x, t, b, c, d) {
	if (t < d/2) return $.easing.easeInBounce(x, t*2, 0, c, d) * .5 + b;
	else return $.easing.easeOutBounce(x, t*2-d, 0, c, d) * .5 + c*.5 + b;
};
// Back
$.easing.easeInBack = function (x, t, b, c, d, s) {
	if (s == undefined) s = 1.70158;
	return c*(t/=d)*t*((s+1)*t - s) + b;
};
$.easing.easeOutBack = function (x, t, b, c, d, s) {
	if (s == undefined) s = 1.70158;
	return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
};
$.easing.easeInOutBack = function (x, t, b, c, d, s) {
	if (s == undefined) s = 1.70158; 
	if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
};
// Elastic
$.easing.easeInElastic = function (x, t, b, c, d, a, p) {
	if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
};
$.easing.easeOutElastic = function (x, t, b, c, d, a, p) {
	if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b);
};
$.easing.easeInOutElastic = function (x, t, b, c, d, a, p) {
	if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
	if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
};
// Circ
$.easing.easeInCirc = function (x, t, b, c, d) { return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; };
$.easing.easeOutCirc = function (x, t, b, c, d) { return c * Math.sqrt(1 - (t=t/d-1)*t) + b; };
$.easing.easeInOutCirc = function (x, t, b, c, d) {
	if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
	return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
};
// Expo
$.easing.easeInExpo = function (x, t, b, c, d) {return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;};
$.easing.easeOutExpo = function (x, t, b, c, d) {return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;};
$.easing.easeInOutExpo = function (x, t, b, c, d) {
	if (t==0) return b;
	if (t==d) return b+c;
	if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
	return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
};
// Sine
$.easing.easeInSine = function (x, t, b, c, d) {return -c * Math.cos(t/d * (Math.PI/2)) + c + b;};
$.easing.easeOutSine = function (x, t, b, c, d) {return c * Math.sin(t/d * (Math.PI/2)) + b;};
$.easing.easeInOutSine = function (x, t, b, c, d) {return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;};
// Quint
$.easing.easeInQuint = function (x, t, b, c, d) {return c*(t/=d)*t*t*t*t + b;};
$.easing.easeOutQuint = function (x, t, b, c, d) {return c*((t=t/d-1)*t*t*t*t + 1) + b;};
$.easing.easeInOutQuint = function (x, t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
	return c/2*((t-=2)*t*t*t*t + 2) + b;
};
// Quart
$.easing.easeInQuart = function (x, t, b, c, d) {return c*(t/=d)*t*t*t + b;};
$.easing.easeOutQuart = function (x, t, b, c, d) {return -c * ((t=t/d-1)*t*t*t - 1) + b;};
$.easing.easeInOutQuart = function (x, t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
	return -c/2 * ((t-=2)*t*t*t - 2) + b;
};
// Cubic
$.easing.easeInCubic = function (x, t, b, c, d) { return c*(t/=d)*t*t + b; };
$.easing.easeOutCubic = function (x, t, b, c, d) { return c*((t=t/d-1)*t*t + 1) + b; };
$.easing.easeInOutCubic = function (x, t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t + b;
	return c/2*((t-=2)*t*t + 2) + b;
};
// Quad
$.easing.easeInQuad = function (x, t, b, c, d) { return c*(t/=d)*t + b; };
$.easing.easeOutQuad = function (x, t, b, c, d) { return -c *(t/=d)*(t-2) + b; };
$.easing.easeInOutQuad = function (x, t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t + b;
	return -c/2 * ((--t)*(t-2) - 1) + b;
};


// })(jQuery)




